const WebSocketServer = require("ws");
const wss = new WebSocketServer.Server({ port: 8002 });
wss.on("connection", (ws, req) => {
  console.log("WebSocket connection");
  // console.log("客户IP：",req);

  ws.on("message", (message,isBinary) => {
    // console.log("WebSocket消息：",message);
    console.log("WebSocket消息：", JSON.parse(message));
    wss.clients.forEach(function each(client) {
      if (client !== ws && client.readyState === WebSocket.OPEN) {
        client.send(message, { binary: isBinary });
      }
    });
  });
});
